var viewer;
var marksIndex = 1; //默认飞行位置下标
var pitchValue = -20; // 相机看点的角度，如果大于0那么则是从地底往上看，所以要为负值
var meter; //计时器
var Exection; //全局时钟事件
var viewerClockMultiplier = 1;
var marks;
var globalPartIndex = -1;
var globalParamter = null;
var pauseParamter = {};
var lastExection = null;
var gototime = 0;
var settime = 0;
var globalTimeout = null;

/**
 * 初始化三维场景
 */
function initScene() {
    //CesiumIonKey
    var key = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MzJjMWZjNi02MmVkLTRkYmUtOGU2ZC0wZDY2ZTAxMzRkMjgiLCJpZCI6MzIxMTYsInNjb3BlcyI6WyJhc2wiLCJhc3IiLCJhc3ciLCJnYyIsInByIl0sImlhdCI6MTU5NjUwOTQ2MX0.gloYT1aON7-sqIUpS82z62k1uE49kfYLmvRon1oxSIM"
    Cesium.Ion.defaultAccessToken = key;

    viewer = new Cesium.Viewer('cesiumContainer', {
        geocoder: true, //是否显示geocoder小器件，右上角查询按钮
        homeButton: true, //是否显示Home按钮
        sceneModePicker: true, //是否显示3D/2D选择器
        baseLayerPicker: true, //是否显示图层选择器
        navigationHelpButton: true, //是否显示右上角的帮助按钮
        animation: false, //是否创建动画小器件，左下角仪表
        creditContainer: "cesiumContainer", // 对应上面div的ID
        timeline: false, //是否显示时间轴
        fullscreenButtion: true, //是否显示全屏按钮
        vrButton: true, //是否显示VR按钮
        selectionIndicator: false, //是否显示选取指示器组件
        // imageryLayers: new Cesium.UrlTemplateImageryProvider({
        //     url: 'http://mt0.google.cn/vt/lyrs=s&hl=zh-CN&x={x}&y={y}&z={z}',
        //     tilingScheme: new Cesium.WebMercatorTilingScheme(),
        //     maximumLevel: 20
        // }),
        // imageryProvider: new Cesium.TileMapServiceImageryProvider({
        //     url: Cesium.buildModuleUrl('Assets/Textures/NaturalEarthII')
        // }),
        imageryProvider: new Cesium.ArcGisMapServerImageryProvider({
            //proxy: new Cesium.DefaultProxy(proxyUrl),
            url: "https://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"
        })
    });
    var thisLayer = new Cesium.CesiumTerrainProvider({
        //url: Cesium.IonResource.fromAssetId(1),
        url: "http://127.0.0.1:9081/map/file/wmts/bil/DSM_NMG_/",
        id: ""
    })
    viewer.scene.terrainProvider = thisLayer;
    viewer.scene.postProcessStages.fxaa.enabled = true; //是否开启抗锯齿
    viewer.scene.fxaa = true; //是否开启抗锯齿
    viewer.scene.fog.enabled = false; //去除云雾效果
    viewer.scene.debugShowFramesPerSecond = true; // 显示帧率
    initViewerMultiplier();
}

/**
 * 初始化场景飞行速度控制器
 */
function initViewerMultiplier() {
    layui.use(['form', 'layer', 'element', 'slider', 'table', 'colorpicker', 'upload'], function() {
        var table = layui.table,
            layer = layui.layer,
            form = layui.form,
            slider = layui.slider,
            element = layui.element,
            upload = layui.upload,
            colorpicker = layui.colorpicker;
        form.render('select');
        form.render('checkbox');
        form.render('radio');
        form.render();
        slider.render({
            elem: '#range_speed',
            min: 0,
            max: 200,
            step: 5,
            value: 100,
            theme: "#1E9FFF",
            tips: true, //关闭默认提示层
            change: function(value) {
                if (value) {
                    viewerClockMultiplier = value / 100;
                    viewer.clock.multiplier = viewerClockMultiplier;
                }
            },
            // setTips: function(value) { //自定义提示文本
            //     return value / 100 + '';
            // }
        });
    });
}